package example.dao;

import java.sql.*;

public class connect {
    //获得数据库连接
    public static Connection getConnection()
    {
        Connection conn = null;
        String driver;
        String url;
        String dbName;
        String password;
        Statement  sta;
        PreparedStatement prepare;
        try
        {
            driver = "com.mysql.jdbc.Driver";
            url = "jdbc:mysql://193.112.145.172:3306/shucai";
            dbName = "shucai";
            password = "11223344wyx";
            Class.forName(driver);
            conn = DriverManager.getConnection(url, dbName, password);
        }
        catch(ClassNotFoundException e)
        {
            e.printStackTrace();
            System.out.println("数据库驱动加载出错");
        }
        catch(SQLException e)
        {
            e.printStackTrace();
            System.out.println("数据库出错");
        }
        return conn;
    }
    //关闭相关通道
    public static void close(ResultSet rs, PreparedStatement p, Connection conn)
    {
        try
        {
            rs.close();
            p.close();
            conn.close();
        }
        catch(SQLException e)
        {
            e.printStackTrace();
            System.out.println("数据关闭出错");
        }
    }

}
